package com.bw.module_service.ui.polling

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.databinding.DataBindingUtil.setContentView
import androidx.viewpager.widget.ViewPager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_common.arouter.Router
import com.bw.lib_common.base.BaseActivity
import com.bw.module_service.R
import com.bw.module_service.adapter.ViewPageAdapter
import com.bw.module_service.databinding.ActivityPollingDetailBinding
import com.bw.module_service.viewmodel.ServiceViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlin.properties.Delegates
@AndroidEntryPoint
@Route(path = Router.Ui.PollingDetailActivity)
class PollingDetailActivity : BaseActivity<ServiceViewModel,ActivityPollingDetailBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_polling_detail
    @Autowired
    @JvmField
    var id:Int=0
    private val mViewModel: ServiceViewModel by viewModels()
    override fun initView() {
        mBinding.vp.adapter= ViewPageAdapter(supportFragmentManager)
        mBinding.bnv.setOnNavigationItemSelectedListener{ item->
            when(item.itemId){
                R.id.inspection_standard->{
                    mBinding.vp.currentItem=0
                    true
                }
                R.id.inspection_record->{
                    mBinding.vp.currentItem=1
                    true
                }
                R.id.work_order_record->{
                    mBinding.vp.currentItem=2
                    true
                }
                else -> false
            }
        }
        mBinding.vp.addOnPageChangeListener(object : ViewPager.OnPageChangeListener{
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
                //页面滑动
            }

            override fun onPageSelected(position: Int) {
                when(position){
                    0->mBinding.bnv.selectedItemId= R.id.inspection_standard
                    1->mBinding.bnv.selectedItemId= R.id.inspection_record
                    2->mBinding.bnv.selectedItemId= R.id.work_order_record

                }
            }

            override fun onPageScrollStateChanged(state: Int) {
                //页面滑动状态改变
            }
        })

        mBinding.back.setOnClickListener { finish() }
    }

    override fun initData() {
        mViewModel.getPollingDetailById(id)
    }

    override fun initListener() {
        mViewModel.PollingDetailLiveData_.observe(this){
            mBinding.projectName.setText("项目名称:"+it.projectId)
            mBinding.pollingIp.setText("点位名称:"+it.pointName)
            mBinding.pollingName.setText("点位位置:"+it.pointLocation)
        }
    }

}